/***************************************************************************
 *   Copyright (C) 2009 by Zheng Yonglei
 *   zhengyonglei@gmail.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/


#ifndef TESTMANAGER_H_
#define TESTMANAGER_H_

#include <QDateTime>

#include <vector>
using namespace std;

#include "WordManager.h"
#include "TestWord.h"
#include "Word.h"

class TestManager : public WordManager
{
public:
	TestManager();
	virtual ~TestManager();

	bool loadTest();
	bool saveTest();

	virtual void finishCurTask();

	bool prepareToTest();
	virtual void addWord(int id);
	bool testNextWord();

	void testFailed();
	void testPassed();
	void curTestFinished();

	void setReviewFrequency();

	TestWord* getCurTestWord();
	TestWord* getTestWord(int id);

	int getActivatedWordCount();
	int getActivatedWordTotalFinishedCount();
	void initActivatedWordTotalTestCount();
	int getActivatedWordTotalTestCount();
	int getWordCountByTestState(TestState status);

	int getTestingWordCount(){return mTestingWordVect.size();}
	int getNewWordCount(){return mNewWordVect.size();}
	int getFinishedWordCount(){return mFinishedWordVect.size();}
	int getTestFinishedFirstCount(){return mTestFinishedFirstVect.size();}

public:
	QTime testElapseTime;
	bool resumeTest;

private:
	void getCurWordTestData();
	void updateCurWordTestData();

	void updateCurWordTrainData();
	void updateTestStateCount();
	void updateTestWordFrozenInfo();
	void selectTestCandidateType();
	int selectTestWord();

private:
	int mTotalTestCount;
	TestState mTestCandidateType;

	QList<int> mTestingWordVect;
	QList<int> mFinishedWordVect;
	QList<int> mNewWordVect;

	QList<int> mTestFinishedFirstVect; //These words should be tested first when candidate type is finished

	int mReviewCycle;
	int mReviewFrequency;
};

#endif /* TESTMANAGER_H_ */
